<?php defined( '_VALID_MOS' ) or die( 'Restricted access' );?>
<form action="index2.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
<TABLE class="adminlist">
<TR>
  <TH colspan="2">New User Subscription</TH>
</TR>

<TR>
  <TD width="100">User:</TD>
  <TD>
  <?php
  if(mosgetparam($_POST,'client')!='JUser'){$where='WHERE j.`block` = 0';}
  $sql = "SELECT j.`name`, j.`username`, j.`email`, j.`id` FROM `#__users` j ".$where." ORDER BY j.`id` ASC";
  global $database;
  $database->setQuery( $sql );
  $users = $database->loadObjectList();
  if(count($users) > 0 )
  {
      if(mosgetparam($_POST,'client')=='JUser'){
        $disabled='disabled="disabled"';
        $cid = mosGetParam( $_REQUEST, 'cid' );
        $i=0;
        $current_id=0;
        while($cid[0]!=$users[$current_id]->id && count($users)!= $current_id)
        {
          $current_id++;
        }
        print sprintf("[%d] %s (%s)", $users[$current_id]->id, $users[$current_id]->username, $users[$current_id]->name);
        print '<input type="hidden" name="user_id" value="'.$users[$current_id]->id.'"> ';
        print '&nbsp;&nbsp;&nbsp;&nbsp;<a href="mailto:'.$users[$current_id]->email.'">'.$users[$current_id]->email.'</a>';
      }
      else {
        foreach($users AS $user)
        {
            $u[] = mosHTML::makeOption( $user->id, sprintf("[%d] %s (%s)", $user->id, $user->username, $user->name), 'id', 'status' );
        }
          echo mosHTML::selectList( $u, 'user_id', 'class="inputbox" '.$disabled, 'id', 'status', $rows[0]->id);
      }
  }      
    ?>
  </TD>
</TR>

<TR>
  <TD width="100">Subscription:</TD>
  <TD>
  <?php
  $sql = "SELECT j.`id`, j.`name`, j.`days`, j.`price` FROM `#__jcs_plans` j WHERE j.`published` = 1 ORDER BY j.`name` ASC";    
  $database->setQuery( $sql );
  $subscr = $database->loadObjectList();
  if(count($subscr) > 0 )
  {
      foreach($subscr AS $subs)
      {
          $s[] = mosHTML::makeOption( $subs->id, sprintf("[%d] %s (\$%s)", $subs->id, $subs->name, $subs->price), 'id', 'status' );
      }
      echo mosHTML::selectList( $s, 'subscr_id', 'class="inputbox"', 'id', 'status', $rows[0]->id);
  } 
  else
  {
      echo "There are no subscription avalible. <a href=\"index2.php?option=com_jcs&task=new\">Create new</a>";
  }     
    ?>
  </TD>
</TR>
<TR>
  <TD>Published</TD>
  <TD><INPUT type="checkbox" name="publish" value="1" /></TD>
</TR>
</table>
<!-- <INPUT type="hidden" name="id" value="<?php echo $cid;?>">-->
<input type="hidden" name="option" value="com_jcs" />
<input type="hidden" name="task" value="" /><?php //echo $task ?>
<input type="hidden" name="hidemainmenu" value="0" />
</form>

